<template>
  <view>
    <view v-for="item in goodList" :key="item.goods_id" @click="gotoDetail(item)">
      <my-goods :goods="item"></my-goods>
    </view>
  </view>
</template>

<script>
  import $http from '../../utils/request';
  export default {
    data() {
      return {
        //查询参数
        query: {
          // 查询关键词
          query: '',
          // 商品分类Id
          cid: '',
          // 页码值
          pagenum: 1,
          // 每页显示多少条数据
          pagesize: 10
        },
        // 数据
        goodList: [],
        total: 0,
        //节流阀
        isBoot: false
      };
    },
    methods: {
      async getGoodData() {
        this.isBoot = true
        const res = await uni.$http.get('api/public/v1/goods/search',this.query)
        //拼接数据
        this.goodList = [...this.goodList,...res.data.message.goods]
        this.total = res.data.message.total
        this.isBoot = false
      },
      gotoDetail(item) {
        uni.navigateTo({
          url: '/subpkg/good_detail/good_detail?goods_is=' + item.goods_id
        })
      }
    },
    // 页面刚加载
    onLoad(op) {
      this.cid = op.cid || ''
      this.query = op.query || ''
      this.getGoodData()
    },
    //触底加载更多数据
    onReachBottom() {
      if (this.isBoot) {
        return 
      }
      if (this.total === this.goodList.length) {
        return uni.showToast({
          title: '数据加载完毕'
        })
      }
      // this.query.pagenum = Number(this.query.pagenum)
      // this.query.pagenum += Number(1)
      // this.getGoodData()
    },
    // 下拉刷新
    onPullDownRefresh() {
      // this.query.pagenum = 1,
      // this.query.pagesize = 10
        this.isBoot = false
        this.getGoodData()
        uni.stopPullDownRefresh()
    }
  }
</script>

<style lang="scss">
  
</style>
